# import os
# import random
# import shutil

# # 原始文件夹和目标文件夹路径
# src_folder = "RCS_opendata/CODA2022-val/images"
# dst_folder = "RCS_opendata/CODA2022-val/images_val"

# # 创建目标文件夹（如果不存在）
# os.makedirs(dst_folder, exist_ok=True)

# # 获取所有文件
# all_files = [f for f in os.listdir(src_folder) if os.path.isfile(os.path.join(src_folder, f))]

# # 检查文件数量是否足够
# if len(all_files) < 2000:
#     raise ValueError(f"源目录中仅有 {len(all_files)} 个文件，不足 2000 个")

# # 随机抽取 200 个文件
# selected_files = random.sample(all_files, 2000)

# # 移动文件
# for f in selected_files:
#     src_path = os.path.join(src_folder, f)
#     dst_path = os.path.join(dst_folder, f)
#     shutil.move(src_path, dst_path)
#     print(f"Moved: {f}")

import os
import shutil

# 路径定义
lidar_dir = 'RCS_opendata/CODA2022-val/images_val'
label_src_dir = 'RCS_opendata/CODA2022-val/labels_yolo'
label_dst_dir = 'RCS_opendata/CODA2022-val/labels_val'    

# 确保目标目录存在
os.makedirs(label_dst_dir, exist_ok=True)

# 遍历lidar文件夹
for filename in os.listdir(lidar_dir):
    if filename.endswith('.jpg'):
        base_name = os.path.splitext(filename)[0]
        npy_filename = base_name + '.txt'
        src_path = os.path.join(label_src_dir, npy_filename)
        dst_path = os.path.join(label_dst_dir, npy_filename)

        if os.path.exists(src_path):
            shutil.move(src_path, dst_path)
            print(f'Moved: {src_path} -> {dst_path}')
        else:
            print(f'[Warning] npy not found for {filename}: {src_path}')
